home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / STDLIB.PAK / INS_ITR.CPP < prev    next >
Text File  |  1997-05-06  |  1KB  |  57 lines

  1.  #include <iterator>
  2.  #include <deque>
  3.  
  4.  using namespace std;
  5.  
  6.  int main ()
  7.  {
  8.    //
  9.    // Initialize a deque using an array.
  10.    //
  11.    int arr[4] = { 3,4,7,8 };
  12.    deque<int> d(arr+0, arr+4);
  13.    //
  14.    // Output the original deque.
  15.    //
  16.    cout << "Start with a deque: " << endl << "     ";
  17.    copy(d.begin(), d.end(), ostream_iterator<int>(cout," "));
  18.    //
  19.    // Insert into the middle.
  20.    //
  21.    insert_iterator<deque<int> > ins(d, d.begin()+2);
  22.    *ins = 5; *ins = 6;
  23.    //
  24.    // Output the new deque.
  25.    //
  26.    cout << endl << endl;
  27.    cout << "Use an insert_iterator: " << endl << "     ";
  28.    copy(d.begin(), d.end(), ostream_iterator<int>(cout," "));
  29.    //
  30.    // A deque of four 1s.
  31.    //
  32.    deque<int> d2(4, 1);
  33.    //
  34.    // Insert d2 at front of d.
  35.    //
  36.    copy(d2.begin(), d2.end(), front_inserter(d));
  37.    //
  38.    // Output the new deque.
  39.    //
  40.    cout << endl << endl;
  41.    cout << "Use a front_inserter: " << endl << "     ";
  42.    copy(d.begin(), d.end(), ostream_iterator<int>(cout," "));
  43.    //
  44.    // Insert d2 at back of d.
  45.    //
  46.    copy(d2.begin(), d2.end(), back_inserter(d));
  47.    //
  48.    // Output the new deque.
  49.    //
  50.    cout << endl << endl;
  51.    cout << "Use a back_inserter: " << endl << "     ";
  52.    copy(d.begin(), d.end(), ostream_iterator<int>(cout," "));
  53.    cout << endl;
  54.  
  55.    return 0;
  56.  }
  57.